// vuex store
import store from '@/store'
import * as Acts from '@/store/consts'
import { isLogined } from '@/service/checkUserLogin'

const routerHook = (bizRouter) => {
	bizRouter.beforeEach((to, from, next) => {
		store.commit(Acts.TOGGLE_LOADING, true);
		if (isLogined() || to.meta.noAuth) {
			next();
		} else {
			location.href = `/login?toUrl=${encodeURIComponent(to.path)}`
		}
	});

	bizRouter.afterEach(to => {
		store.commit(Acts.TOGGLE_LOADING, false);
	});

	return bizRouter
}

export default routerHook